/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            shopIndexInfo: {
                products: [],
                shopVisitCount: '',
                waitShopOrderCount: '',
                returnOrderCount: '',
                todayMoney: '',
                sevenDay: [],
                sevenDayDatas: []
            }
        },
        _initMethod: function () {
            if (vc.getCurrentCommunity()) {
                $that._queryHotProduct();
                $that._getTodayData();
            }
        },
        _initEvent: function () {
            vc.on('shopIndex', 'initData', function () {
                $that._queryHotProduct();
                $that._getTodayData();
            });
        },
        methods: {
            _queryHotProduct: function () {
                ///product/queryHotProduct
                var param = {
                    params: {
                        page: 1,
                        row: 10,
                        shopId: vc.getCurrentCommunity().shopId,
                    }
                };
                //发送get请求
                vc.http.apiGet('/product/queryHotProduct',
                    param,
                    function (json) {
                        var _shopInfo = JSON.parse(json);
                        let _products = _shopInfo.data;
                        if (_products) {
                            _products.forEach(product => {
                                    let _productSpecValues = product.productSpecValues;
                                    if (_productSpecValues) {
                                        _productSpecValues.forEach(item => {
                                            let _productSpecDetails = item.productSpecDetails;
                                            let _specValue = '';
                                            if (_productSpecDetails) {
                                                _productSpecDetails.forEach(detail => {
                                                    _specValue += (detail.detailValue + "/");
                                                });
                                            }
                                            item.specValue = _specValue;
                                            product.specName = _specValue;
                                        });
                                    }
                                }
                            )
                        }
                        $that.shopIndexInfo.products = _products;
                    }, function () {
                        console.log('请求失败处理');
                    }
                );
            },
            _getTodayData: function () {
                ///product/queryHotProduct
                var param = {
                    params: {
                        page: 1,
                        row: 10,
                        shopId: vc.getCurrentCommunity().shopId,
                    }
                };
                //发送get请求
                vc.http.apiGet('/index/getTodayData',
                    param,
                    function (json) {
                        var _shopInfo = JSON.parse(json);
                        let _products = _shopInfo.data;
                        vc.copyObject(_products, $that.shopIndexInfo)
                        $that._initShopUserEcharts();
                    }, function () {
                        console.log('请求失败处理');
                    }
                );
            },
            _initShopUserEcharts: function () {
                let dom = document.getElementById("userEchatjs");
                let myChart = echarts.init(dom);
                let option = null;
                option = {
                    xAxis: {
                        type: 'category',
                        data: $that.shopIndexInfo.sevenDay.reverse()
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        data: $that.shopIndexInfo.sevenDayDatas.reverse(),
                        type: 'line',
                        smooth: true
                    }]
                };
                if (option && typeof option === "object") {
                    myChart.setOption(option, true);
                }
            },
        }
    });
})(window.vc);
